// 全选
function checkBox(name,checked){
    //全选开始
    $("input[name='"+name+"']").prop("checked", checked);
}
// 同步数据
function syncNode() {
    bootbox.confirm({
        title: "操作提示",
        size: "small",
        message: "你确定要同步数据吗？",
        callback: function (result) {
            if (result) {
                $.ajax({
                    type : "POST",
                    cache : false,
                    url : "/admin/models/syncData",
                    contentType: "application/x-www-form-urlencoded;charset=utf-8",
                    dataType:"json",
                    success: function (result) {
                        if (result.errorCode == 'y') {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'success',
                                time: 2000
                            }).show();
                        } else {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'danger',
                                time: 2000
                            }).show();
                        }
                    },error : function(result) {
                        new $.zui.Messager('提示消息：' + result.errorText, {
                            icon: 'exclamation-sign',
                            type: 'danger',
                            time: 2000
                        }).show();
                    }
                });
            }
        }
    });
}
// 创建模型
function addNode() {
    window.location.href = "/admin/models/newModel";
}
// 编辑模型
function editNode(id) {
    window.location.href = "/editor?modelId=" + id;
}
// 删除模型
function deleteNode(id) {
    // 定义一个存放id集合的数组
    bootbox.confirm({
        title: "操作提示",
        size: "small",
        message: "你确定要删除选择的数据吗？",
        callback: function (result) {
            if (result) {
                $.ajax({
                    type : "DELETE",
                    cache : false,
                    url : "/admin/models/" + id,
                    contentType: "application/x-www-form-urlencoded;charset=utf-8",
                    dataType:"json",
                    success: function (result) {
                        if (result.errorCode == 'y') {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'success',
                                time: 2000
                            }).show();
                            // 一秒后跳转
                            setTimeout("location.reload()", 1000);
                        } else {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'danger',
                                time: 2000
                            }).show();
                        }
                    },error : function(result) {
                        new $.zui.Messager('提示消息：' + result.errorText, {
                            icon: 'exclamation-sign',
                            type: 'danger',
                            time: 2000
                        }).show();
                    }
                });
            }
        }
    });
}
// 部署模型
function deploymentNode(id) {
    // 定义一个存放id集合的数组
    bootbox.confirm({
        title: "操作提示",
        size: "small",
        message: "你确定要部署选择的数据吗？",
        callback: function (result) {
            if (result) {
                $.ajax({
                    type : "POST",
                    cache : false,
                    url : "/admin/models/" + id,
                    contentType: "application/x-www-form-urlencoded;charset=utf-8",
                    dataType:"json",
                    success: function (result) {
                        if (result.errorCode == 'y') {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'success',
                                time: 2000
                            }).show();
                            // 一秒后跳转
                            setTimeout("location.reload()", 1000);
                        } else {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'danger',
                                time: 2000
                            }).show();
                        }
                    },error : function(result) {
                        new $.zui.Messager('提示消息：' + result.errorText, {
                            icon: 'exclamation-sign',
                            type: 'danger',
                            time: 2000
                        }).show();
                    }
                });
            }
        }
    });
}
// 导出模型XML
function exportNode(id) {
    bootbox.confirm({
        title: "操作提示",
        size: "small",
        message: "你确定要导出选择的数据吗？",
        callback: function (result) {
            if (result) {
                document.location.href="/admin/models/export/" + id;
                new $.zui.Messager('提示消息：' + "导出成功", {
                    icon: 'exclamation-sign',
                    type: 'success',
                    time: 2000
                }).show();
            }
        }
    });
}
